<!DOCTYPE html>
<html lang="en">
<head>
    <title>{dede:global.cfg_webname/}</title>
    {dede:include filename="common_head.htm"/}
</head>
<body>
    <div class="main-wrap index-wrap about-wrap book-wrap">
        {dede:include filename="header.htm"/}
        {dede:include filename="banner_inner.htm"/}
        <div class="content">
            {dede:include filename="inner_content_nav.htm" /}
            <div class="content-con-wrap news-content book-content">
                <ul class="list-wrap clearfix news-list-wrap">
                    <li class="list-item news-list-item flex rsb wow slideInUp1">
                        <div class="pic-wrap news-img-wrap mobile-content none right-img-wrap flex-1 wow slideInUp1">
                            <img src="{dede:field.typeicon /}" alt="" class="pic-img news-img" />
                        </div>
                        <div class="news-info-wrap flex flex-1">
                            <div class="context-wrap">
                                <div class="info-content">
                                    <form id="guest-form">
                                        <ul class="form-wrap book-form-wrap">
                                            <li class="form-item flex rcs">
                                                <div class="form-item-label">Name (University Or Enterprise):</div>
                                                <input type="text" name="username" id="username" class="form-item-input" />
                                            </li>
                                            <li class="form-item flex rcs">
                                                <div class="form-item-label">Number Of Visitors:</div>
                                                <input type="text" name="num" id="num" class="form-item-input" />
                                            </li>
                                            <li class="form-item flex rcs">
                                                <div class="form-item-label">Visiting Time:</div>
                                                <input type="text" name="time" id="time" class="form-item-input" />
                                            </li>
                                            <li class="form-item flex rcs">
                                                <div class="form-item-label">Contacts:</div>
                                                <input type="text" name="contact" id="contact" class="form-item-input" />
                                            </li>
                                            <li class="form-item flex rcs">
                                                <div class="form-item-label">Tel:</div>
                                                <input type="text" name="mobile" id="mobile" class="form-item-input" />
                                            </li>
                                            <li class="form-item flex rcs">
                                                <div class="form-item-label">Note:</div>
                                                <input type="text" name="other" id="other" class="form-item-input" />
                                            </li>
                                        </ul>
                                    </form>
                                    <div class="error-tips-wrap">
                                        <div class="error-tips"></div>
                                    </div>
                                    <div class="btn-wrap">
                                        <div class="btn-item submit-btn-item flex ccc cur-p" onclick="submitApply();">Submit</div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="pic-wrap news-img-wrap pc-content right-img-wrap flex-1 wow slideInUp1">
                            <img src="{dede:field.typeicon /}" alt="" class="pic-img news-img" />
                        </div>
                    </li>
                </ul>
            </div>

        </div>
        {dede:include filename="footer.htm"/}
        {dede:include filename="common_script.htm"/}
    </div>
    <div class="popup-wrap none">
        <div class="popup-content flex ccc h100">
            <div class="result-content-wrap flex ccc text-c">
                <div class="pic-wrap pos-a close-btn-item cur-p" onclick="closePopup();">
                    <img src="{dede:global.cfg_templets_skin/}/icon/icon_close.png" alt="" class="pic-img btn-icon" />
                </div>
                <img src="{dede:global.cfg_templets_skin/}/icon/icon_success.png" alt="" class="pic-img result-img" />
                <div class="result-title">Submitted Successfully</div>
            </div>
        </div>
    </div>
    <script>
        var formWrap = $('.form-content-wrap');


        // 提交申请
        function submitApply() {

            var windowWidth = $(window).width();
            if (windowWidth < 650) {
                layerSize = ['80vw', '60vw'];
            } else {
                layerSize = ['600px', '400px'];
            }

            // layer.open({
            //     type: 1,
            //     closeBtn: 0,
            //     title: false,
            //     shadeClose: true,
            //     skin: 'yourclass',
            //     area: layerSize,
            //     content: $('.popup-wrap').html(),
            // });


            var _username = $('#username'),
                _usernameVal = _username.val();

            var _num = $('#num'),
                _numVal = _num.val();

            var _time = $('#time'),
                _timeVal = _time.val();

            var _contact = $('#contact'),
                _contactVal = _contact.val();

            var _mobile = $('#mobile'),
                _mobileVal = _mobile.val();

            var _other = $('#other'),
                _otherVal = _other.val();

            var _errorWrap = $('.error-tips-wrap'),
                _errorTips = _errorWrap.find('.error-tips');

            var _dateStr = new Date(),
                _currentDate = _dateStr.Format("yyyy-MM-dd hh:mm:ss");


            if (_usernameVal == '') {
                _errorWrap.addClass('cur');
                _errorTips.text('* Name cannot be empty');
                _username.focus();
                return false;
            }

            if (_numVal == '') {
                _errorWrap.addClass('cur');
                _errorTips.text('* Number of visitors cannot be empty');
                _num.focus();
                return false;
            }

            if (_timeVal == '') {
                _errorWrap.addClass('cur');
                _errorTips.text('* Visit time cannot be empty');
                _time.focus();
                return false;
            }

            if (_contactVal == '') {
                _errorWrap.addClass('cur');
                _errorTips.text('* Contact cannot be empty');
                _contact.focus();
                return false;
            }

            if (_mobileVal == '') {
                _errorWrap.addClass('cur');
                _errorTips.text('* Contact information cannot be empty');
                _mobile.focus();
                return false;
            } else if (!/^1[0-9]{10}/.test(_mobileVal)) {
                _errorWrap.addClass('cur');
                _errorTips.text('* Wrong format of mobile phone number');
                _mobile.focus();
                return false;
            }


            var dataString =
                'username=' + _usernameVal +
                '&num=' + _numVal +
                '&time=' + _timeVal +
                '&contact=' + _contactVal +
                '&mobile=' + _mobileVal +
                '&other=' + _otherVal +
                '&create_time=' + _currentDate +
                '&action=post' +
                '&diyid=1&do=2' +
                '&dede_fields=username,text;num,text;time,text;contact,text;mobile,text;other,text;create_time,text' +
                '&dede_fieldshash=f4d08e575cc448b7d5fb528c82959bb8';

            $.ajax({
                type: "POST",
                url: "/plus/diy.php",
                data: dataString,
                success: function(data) {
                    $('#guest-form')[0].reset();
                    _errorWrap.removeClass('cur');
                    layer.open({
                        type: 1,
                        closeBtn: 0,
                        title: false,
                        shadeClose: true,
                        skin: 'yourclass',
                        area: layerSize,
                        content: $('.popup-wrap').html(),
                    });
                }
            });
            return false;
        }

        // 关闭弹窗
        function closePopup() {
            layer.closeAll();
        }

    </script>
</body>
</html>